package hot100;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class Lc128 {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>(nums.length);
        for (int i : nums) {
            set.add(i);
        }

        int ret = 0;
        int cur = 0;
        for (int num : set) {
            if (set.contains(num - 1)) {
                continue;
            }
            int tmp = num;
            while (set.contains(tmp)) {
                tmp++;
                cur++;
            }
            ret = Math.max(ret, cur);
            cur = 0;
        }
        return ret;
    }
}
